/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tg.cms.entity;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import telsoft.admin.util.AppServer;
import telsoft.sql.Database;
import telsoft.util.StringUtil;

/**
 *
 * @author tuanta
 */
public class MDItem {
    String name;
    String itemID;
    long categoryID;
    long publisherID;
    long viewCount;
    long downloadCount;
    String lastUpdated;
    Properties prtItemProperties;
    Connection cn;

    public Connection getCn() {
        return cn;
    }

    public void setCn(Connection cn) {
        this.cn = cn;
    }
    public String getProperty(String name){
        if(prtItemProperties==null)
            return "";
        else return prtItemProperties.getProperty(name);
    }
    public String getItemID() {
        return itemID;
    }

    public void setItemID(String itemID) {
        this.itemID = itemID;
    }

    public Properties getPrtItemProperties() {
        return prtItemProperties;
    }

    public void setPrtItemProperties(Properties prtItemProperties) {
        this.prtItemProperties = prtItemProperties;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getCategoryID() {
        return categoryID;
    }

    public void setCategoryID(long categoryID) {
        this.categoryID = categoryID;
    }

    public long getPublisherID() {
        return publisherID;
    }

    public void setPublisherID(long publisherID) {
        this.publisherID = publisherID;
    }

    public long getViewCount() {
        return viewCount;
    }

    public void setViewCount(long viewCount) {
        this.viewCount = viewCount;
    }

    public long getDownloadCount() {
        return downloadCount;
    }

    public void setDownloadCount(long downloadCount) {
        this.downloadCount = downloadCount;
    }

    public String getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(String lastUpdated) {
        this.lastUpdated = lastUpdated;
    }
    public void queryItemById() throws Exception{
        Statement stmt = null;
        ResultSet rsItem = null;
        ResultSet rsProperty = null;
        
        String strSQL = "SELECT  * FROM MD_ITEMS WHERE ITEM_ID = " + getItemID();
        String strSQLProperties = "SELECT  * FROM MD_ITEM_PROPERTIES WHERE ITEM_ID = " + getItemID();
        try {
            stmt = cn.createStatement();
            rsItem = stmt.executeQuery(strSQL);
            while(rsItem.next()){
                setCategoryID(rsItem.getLong("category_id"));
                setPublisherID(rsItem.getLong("publisher_id"));
            }
            rsProperty = stmt.executeQuery(strSQLProperties);
            Properties prt = new Properties();
            while(rsProperty.next()){
                prt.put(rsProperty.getString("property_name"), StringUtil.nvl(rsProperty.getString("property_value"),""));
            }
            setPrtItemProperties(prt);
        }
        finally{
            Database.closeObject(stmt);
        }
    }
}
